﻿using System.Net.Sockets;
using System.IO;

namespace org.syncsoft.overalt.gui.contextMenu
{
    public class Socket
    {
        private const string strToken = "#";
        public Socket()
        {
            Client = new TcpClient("127.0.0.1", 1003);
            NetStream = Client.GetStream();
            StrWriter = new StreamWriter(NetStream);
            StrReader = new StreamReader(NetStream);
        }
        private TcpClient Client { get; set; }
        private NetworkStream NetStream { get; set; }
        private StreamWriter StrWriter { get; set; }
        private StreamReader StrReader { get; set; }

        public void Send(int id, string path, string[] fileNames)
        {
            try
            {
                string msg = id + strToken + path + strToken;
                //if (fileNames.Length > 0 || fileNames != null)
                //{
                //    System.Windows.Forms.MessageBox.Show("Entra no IF");
                //    foreach (string item in fileNames)
                //    {
                //        msg += item.ToString();
                //    }
                //}
                StrWriter.WriteLine(msg + " ");
                StrWriter.WriteLine("quit");
                StrWriter.Flush();
                StrWriter.Close();
                NetStream.Close();
            }
            catch (System.Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.Message.ToString());
            }
        }
    }
}
